#!/usr/bin/env python 
# -*- coding:utf-8 -*-
import mysql.connector
import random
db_connect = mysql.connector.connect(
    host='8.142.105.62',
    user='root',
    passwd='123456',
    database='test',
    charset='utf8'
)

db = db_connect.cursor(dictionary=True)
db.execute("select * from user ")
rows = db.fetchall()
count = 0

try:
    for row in rows:
        count +=1
        year = random.randint(1949, 2022)
        month = random.randint(10, 12)
        day = random.randint(10, 20)
        end_num = random.randint(1000, 3000)
        num = random.randint(10000000, 99999999)
        idcard = '410426' + str(year) + str(month) + str(day) + str(end_num)
        phone = '176' + str(num)

        sql = "update user set phone = %s,idcard = %s where id = %s"
        val = (phone,idcard,row['id'])
        db.execute(sql,val)
    db_connect.commit()
except:
    db_connect.rollback()

print(count, " 条记录被修改")